// pages/detail/detail.js
var WxParse = require("../../wxParse/wxParse.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    aouther:"",
    maketime:"",
    readynum:0,
    contents:"",
    title:"",
    user_avatar :"",
    article_id:"",
    pl_arrs:[],
    has:false
  },

  pinglun:function(e){
    var article_id = e.currentTarget.dataset.arcitle;
    wx.redirectTo({
      url: '/pages/pinglun/pinglun?article_id=' + article_id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    var article_id = options.article_id;
    wx.showToast({
      title: '加载中',
      icon: "loading"
    })
    wx.request({
      url: 'https://lgn.xiangxueweilai.com/index.php/article',
      method: "POST",
      data: { article_id: article_id },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      complete() {
        wx.hideLoading()
      },
      success: res => {
        console.log(res);
        if (res.data.status == 1) {
          
          var content = res.data.result.content
          WxParse.wxParse('article', 'html', content, that, 5);

          that.setData({
            aouther: res.data.result.author,
            maketime: res.data.result.add_time,
            readynum: res.data.result.click,
            contents: res.data.result.content,
            title: res.data.result.title,
            article_id: article_id
          })
        }

      }
    })

    wx.request({
      url: 'https://lgn.xiangxueweilai.com/index.php/pl_list',
      method: "POST",
      data: { article_id: article_id },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        if (res.data.status == 1) {
          this.setData({
            pl_arrs: res.data.result,
            has : true
          })
        }

      }
    })



    wx.getStorage({
      key: 'user',
      success: function(res) {
        console.log(res.data.avatarUrl);
        that.setData({
          user_avatar: res.data.avatarUrl
        });
      },
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})